<?php
class Comment extends AppModel {
// Define the model and it's associations:
var $name = 'Comment';
var $hasMany = array(
			'Comment' => array(
				'className' => 'Rating',
				'foreignKey' => 'object_ID',
				'dependent' => 'true'
				)
			);
var $belongsTo = array(
				'Pothole' => array(
					'className' => 'Pothole',
					'foreignKey' => 'object_ID'
					)
				);
	/*
	// Get all comments associated with this object ID
	*/
	public function getComments($obj_id) {
		$comments = $this->find('all', array(
			'conditions' => array(
				'Comment.object_id' => $obj_id)));
		return $comments;
	}
	
	/*
	/	countComments: Counts the number of comments on 
	/		pages, comments or currently-active potholes
	/		in a given town.
	/	string $object_id: ID of the object whose comments
	/		are to be counted.
	/	string $mode: pothole, comment, page
	*/
	public function countComments($object_id, $mode = 'pothole') {
		$conditions = array('Comment.object_ID' => $object_id);
		switch($mode) {
			case 'pothole':
				$conditions['Comment.object_id'] = 'Pothole.ID';
				$conditions['Pothole.status NOT LIKE'] = 'Closed';
				break;
			case 'page':
				$conditions['Comment.object_id'] = 'Page.ID';
				$conditions['Page.status NOT LIKE'] = 'Closed';
				break;
		}
		$count = $this->find('count', array('conditions' => $conditions));
		return $count;
	}
}
?>
